import { ref, reactive } from 'vue'
  export default  class Validate{
    constructor(){
      this.ruleForm = reactive({
        username: '',
        phone: '',
        sex: '',
        pwd1: '',
        pwd2: '',
        agree: false
      })

      this.rules = reactive({
        username: [
          {
            required: true,
            trigger: 'blur',
            message: '不能为空'
          }
        ],
        phone: [
          {
            required: true,
            trigger: 'blur',
            message: '不能为空'
          },
          {
            pattern: /^1[3-9]\d{9}/,
            trigger: 'blur',
            message: '手机号格式有误'
          }
        ],
        sex: [
          {
            required: true,
            trigger: 'blur',
            message: '不能为空'
          },
          {
            pattern: /1|0/,
            message: '性别格式有误'
          }
        ],
        pwd1: [
          {
            required: true,
            trigger: 'blur',
            message: '不能为空'
          }
        ],
        pwd2: [
          {
            required: true,
            trigger: 'blur',
            message: '不能为空'
          },
          {
            validator: (rule, value, callback) => {
              if (value !== this.ruleForm.pwd1) {
                callback(new Error('两次密码不一致'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ],
        agree: [
          {
            validator: (rule, value, callback) => {
              if (!value) {
                callback(new Error('请勾选用户使用协议'))
              } else {
                callback()
              }
            },
            trigger: 'blur'
          }
        ]
      
      })
    }  
  }